package com.heima.article.controller.v1;

import com.heima.api.behavior.BehaviorClient;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ApArticleDto;
import com.heima.model.article.dtos.ApArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.vos.ApArticleVo;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.UserRelationDto;
import com.heima.model.user.pojos.ApUserFollow;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/3/14 9:47
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private ApArticleService articleService;

    @Autowired
    private BehaviorClient behaviorClient;

    @PostMapping("/load")
    public ResponseResult load(@RequestBody ApArticleHomeDto homeDto) {
        return articleService.load(homeDto, ArticleConstants.LOAD_MORE);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ApArticleHomeDto homeDto) {
        return articleService.load(homeDto, ArticleConstants.LOAD_MORE);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ApArticleHomeDto homeDto) {
        return articleService.load(homeDto, ArticleConstants.LOAD_NEW);
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApArticleDto articleDto) {
        return articleService.saveArticle(articleDto);
    }

    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody UserRelationDto dto) {
        return articleService.loadArticleBehavior(dto);
    }

    @GetMapping("/Article/{id}")
    public ApArticle findArticleById(@PathVariable("id") Long id) {
        if (id == null) {
            return null;
        }
        return articleService.getById(id);
    }

}